package com.stationpc.androidtvrecents

import android.animation.Animator
import android.animation.AnimatorListenerAdapter
import android.view.View
import androidx.recyclerview.widget.DefaultItemAnimator
import androidx.recyclerview.widget.RecyclerView

class RecentAppsAnimator : DefaultItemAnimator() {
    init {
        supportsChangeAnimations = false
        addDuration = 200L
        removeDuration = 200L
        moveDuration = 200L
    }

    override fun animateRemove(holder: RecyclerView.ViewHolder): Boolean {
        holder.itemView.animate()
            .alpha(0f)
            .scaleX(0.8f)
            .scaleY(0.8f)
            .setDuration(removeDuration)
            .setListener(object : AnimatorListenerAdapter() {
                override fun onAnimationEnd(animation: Animator) {
                    holder.itemView.apply {
                        alpha = 1f
                        scaleX = 1f
                        scaleY = 1f
                    }
                    dispatchRemoveFinished(holder)
                }
            })
        return true
    }
}
